<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class index extends baseController {

	public function __construct(){
		parent::__construct();
		$this->load->model('project_Model', 'projectModel', true);
	}
	public function index()
	{
		$datatemp = array(
				'PROJ' => $this->projectModel->getProjectByID(1)
		);
		$data = array(
				'content' => $this->loadStatic('project/myproject',$datatemp)
		);
		$this->loadView($data);
	}
	
	public function loadProject($projectid =null)
	{
	if($projectid == null) $projectid = 1;
		$datatemp = array(
				'PROJ' => $this->projectModel->getProjectByID($projectid)
		);
		$data = array(
				'content' => $this->loadStatic('project/myproject',$datatemp)
		);
		$this->loadView($data);
	}
	
	public function save(){
		try {
			$fName = $this->input->post('f_name');
			
			
			if(isset($fName) && !is_null($fName)){
				$dataProject = array(
						'user_id'=> $this->session->userdata('userID')
				);
				$dataPost = $this->input->post();
					
				
				$projectId = $this->input->post('project_id');
				
				
				/////// new vproject?
				if(is_null($projectId) || empty($projectId)){
					$this->projectModel->insert($dataProject);
					$dataPost['project_id'] = mysql_insert_id();
				}
				// $dataPost['project_id']; ok
				$projectId = $dataPost['project_id'];
		
				
				
				$data = array();
				unset($dataPost['project_id']);
				unset($dataPost['f_name']);
				$redir = $dataPost['redir'];
				unset($dataPost['redir']);
				
				
				foreach ($dataPost as $key => $value){
					$data[$key] = $value;
				}
				$this->projectModel->updateProjectByID($projectId,$data);
				redirect(site_url('project/' . $projectId));
			}
			
		} catch (Exception $e) {
			throw $e;
		}
	}
	

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */